package com.oba.king.sysmanager.log;

import java.util.HashMap;
import java.util.Map;

import com.oba.king.controlmanage.ProxyContract;
import com.oba.king.datalib.AccountValues;
import com.oba.king.datalib.CompanyInfo;
import com.oba.king.datalib.Customer;
import com.oba.king.datalib.RecieverInfo;
import com.oba.king.datalib.creditcontrol.CreditControl;
import com.oba.king.datalib.deliverytype.DeliveryType;
import com.oba.king.datalib.paymenttype.PaymentType;
import com.oba.king.sysmanager.Dept;

public class TableService {

	private static TableService service;
	private Map<Integer, TableInfo> map;
	private Map<String, Integer> searchMap;

	private TableService() {
		initMap();
	}

	public static TableService getInit() {
		if (service == null) {
			service = new TableService();
		}
		return service;
	}

	private void initMap() {
		map = new HashMap<Integer, TableInfo>();
		searchMap = new HashMap<String, Integer>();
		add(Dept.class,"DEPARTMENT","部门","公司的部门信息");
		add(ProxyContract.class,"PROXYCONTRACT","代理协议","代理协议信息");
		add(AccountValues.class,"ACCOUNTVALUES","账户","代理商账户信息");
		add(CompanyInfo.class,"COMPANYINFO","公司","公司信息");
		add(Customer.class,"CUSTOMER","代理商","代理商信息");
		add(RecieverInfo.class,"RECIEVERINFO","收货人","收货人信息");
		add(DeliveryType.class,"DELIVERYTYPE","发货方式","发货方式");
		add(PaymentType.class,"PAYMENTTYPE","付款方式","付款方式");
		add(CreditControl.class,"CREDITCONTROL","信用控制","信用控制");
	}

	private void add(Class c, String tableName, String tableFullName,
			String tableDesc) {
		TableInfo ti = new TableInfo(c,tableName,tableFullName,tableDesc);
		map.put(ti.getCode(), ti);
		searchMap.put(tableFullName, ti.getCode());
	}
	
	public TableInfo getTableInfo(Integer code) {
		return map.get(code);
	}
	
	public Integer getCodeByName(String tableFullName) {
		return searchMap.get(tableFullName);
	}

}
